package com.min.juc.lock8;

import java.util.concurrent.TimeUnit;

/**
 * 静态方法的时候
 */
public class Test3 {
    public static void main(String[] args) {
//        Phone3 phone = new Phone3();

        // A,B线程肯定会顺序执行
        // synchronized 哪个线程先拿到锁,会锁住对象
        // 必须执行有synchronized 才会拿到锁
        new Thread(()->{
            Phone3.sendSms();
        },"A").start();

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        new Thread(()->{
            Phone3.call();
        },"B").start();


    }
}


class Phone3 {

   public static synchronized void  sendSms(){
       try {
           TimeUnit.SECONDS.sleep(2);
       } catch (InterruptedException e) {
           e.printStackTrace();
       }
       System.out.println("发短信");
   }
   public static synchronized void  call(){
       System.out.println("打电话");
   }
}